<?php
namespace app\admin\controller;

use app\extra\ApiToken;
use think\facade\Request;
/**
 * @title 退出登陆
 * @description 管理员默认账号是:admin, 密码：admin123
 * @group admin
 */
class OutLogin extends Base
{
    /**
     * @title 退出登录
     * @description 接口说明
     * @author hardy
     * @url /admin/OutLogin
     * @method GET
     * @header name:authorization require:1 default: desc:登陆的token
     */
    public function gets()
    {
        ApiToken::set(self::$_login_key, null);
        $this->responseSuccess();
    }
    /**
     * @title 销毁账号
     * @description 接口说明
     * @author hardy
     * @url /admin/OutLogin
     * @method delete
     * @header name:authorization require:1 default: desc:登陆的token
     */
    public function delete(){
        $id = $this->getUserAttr('id');
        if ($id == 1){
            $this->responseFail('初始超级管理员，无法销毁！');
        }
        $model = model('Admin');
        $r = $model->deleteData($id);
        if ($r == false){
            $this->responseFail($model->getError());
        }
        ApiToken::set(self::$_login_key, null);
        sysLogs('管理员自动注销账号', '删除id：'.$id);
        $this->responseSuccess();
    }
}